// 登录业务
const form = document.querySelector('form')
const btnLogin = document.querySelector('#btn-login')
btnLogin.addEventListener('click', async function () {
    const date = serialize(form, { hash: true, empty: true })
    const { username, password } = date
    if (username.length < 8 || username.length > 30) {
        return myAlter('用户名应在8~30位之间')
    }
    if (password.length < 6 || password.length > 30) {
        return myAlter('密码在6~30位之间')
    }
    const res = await axios.post('/login', date)
    const { data: { message, data } } = res
    localStorage.setItem('username', username)
    console.log(data);

    localStorage.setItem('token', data.token)
    myAlter(message)
    setTimeout(() => {
        location.href = 'index.html'
    }, 1500);
})